package com.zhida.smartcontrol.dialog.tdkgdialog;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.jay.tools.recycler.MultipleViewHolder;
import com.jay.tools.recycler.SingleRecyclerAdapter;
import com.zhida.smartcontrol.R;

import java.util.List;

public class TdkgAdapter extends SingleRecyclerAdapter<SwitchBean> {

    public TdkgAdapter(@Nullable List<SwitchBean> data) {
        super(R.layout.item_dialog_tdkg, data);
    }

    @Override
    protected void convert(MultipleViewHolder holder, SwitchBean info) {
        LinearLayout item = holder.getView(R.id.ll_item);
        TextView tvItem = holder.getView(R.id.tv_item);
        Switch aSwitch = holder.getView(R.id.switch_view);

        tvItem.setText(info.getName());
        aSwitch.setChecked(info.isCheck());

        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mListener) {
                    for (SwitchBean bean : mData) {
                        bean.setCheck(!bean.isCheck());
                    }
                    mListener.onClick(info, 0);
                    notifyDataSetChanged();
                }
            }
        });

    }
}
